package com.pengweiwei.androidzygote.main.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pengweiwei.androidzygote.databinding.ActivityFeedbackBinding;
import com.pengweiwei.androidzygote.mine.data.MineApiHelper;
import com.putong35.common.baseactfrag.activity.BaseActivity;
import com.putong35.common.utils.EasyToast;

public class FeedbackActivity extends BaseActivity {

    public static void start(Context context) {
        Intent starter = new Intent(context, FeedbackActivity.class);
        context.startActivity(starter);
    }

    ActivityFeedbackBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("问题反馈");
        enableBackButton();
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = ActivityFeedbackBinding.inflate(getLayoutInflater());
        binding.setVm(this);
//        String appInfo = getString(R.string.app_name) + ":" + AppUtil.getVersionName(this);
//        activityAboutBinding.setAppInfo(appInfo);
        binding.etContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                int length = binding.etContent.length();
                binding.tvLength.setText(length + "/200");

            }
        });
        return binding.getRoot();
    }


    public void clkFeedback() {
        String feedbackContent = binding.etContent.getText().toString();
        if (TextUtils.isEmpty(feedbackContent)) {
            EasyToast.showToast(this, "请输入意见反馈");
            return;
        }
        int type = binding.rbtType1.isChecked() ? 1 : binding.rbtType2.isChecked() ? 2 : binding.rbtType3.isChecked() ? 3 : 4;
        MineApiHelper.feedback(feedbackContent, type, (code, msg, data, extObj) -> {
            EasyToast.showToast(FeedbackActivity.this, "提交成功！");
            finish();
        }, (errCode, msg) -> EasyToast.showToast(FeedbackActivity.this, "提交失败：" + msg));
    }



}
